package com.qifenqian.turbot.module.ui.order.table

import android.os.Bundle
import android.support.v7.widget.GridLayoutManager
import android.view.View
import com.qifenqian.turbot.R
import com.qifenqian.turbot.base.BaseFragment
import com.qifenqian.turbot.module.adapter.itemdecoration.GridItemDecoration
import com.qifenqian.turbot.module.adapter.order.OrderTableAdapter
import com.qifenqian.turbot.module.contract.OrderContract
import com.qifenqian.turbot.module.entity.response.order.OrderTableEntity
import com.qifenqian.turbot.module.presenter.OrderPresenter
import kotlinx.android.synthetic.main.fragment_order_table.view.*

private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

class TableFragment : BaseFragment<OrderPresenter, OrderContract.View>(), OrderContract.View {

    companion object {
        @JvmStatic
        fun newInstance(param1: String, param2: String) = TableFragment().apply {
            arguments = Bundle().apply {
                putString(ARG_PARAM1, param1)
                putString(ARG_PARAM2, param2)
            }
        }
    }

    override fun bindLayoutId(): Int {
        return R.layout.fragment_order_table
    }

    override fun bindPresenter(): OrderPresenter? {
        return OrderPresenter(activity!!, this)
    }

    private var param1: String? = null
    private var param2: String? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            param1 = it.getString(ARG_PARAM1)
            param2 = it.getString(ARG_PARAM2)
        }
    }

    private var mOrderTableEntities = mutableListOf<OrderTableEntity>(
            OrderTableEntity(0, "A1", 0, 2, 5, true),
            OrderTableEntity(0, "A2", 1, 2, 5, false),
            OrderTableEntity(0, "A3", 1, 3, 8, false),
            OrderTableEntity(0, "A4", 0, 1, 4, true),
            OrderTableEntity(0, "A5", 1, 1, 4, true),
            OrderTableEntity(0, "A6", 0, 8, 14, false)
                                                                     )

    override fun initial(view: View) {
        view.rv_order_table.layoutManager = GridLayoutManager(activity!!, 4)
        view.rv_order_table.addItemDecoration(GridItemDecoration(activity!!, 16))
        view.rv_order_table.adapter = OrderTableAdapter(mOrderTableEntities)
    }

}
